;; _cond_gen 'cond|'then|'else='body|'para

(load "cn-if-merge.lisp")

(defun cond-condp(cond-)
  (or (eql cond- 'cond) (eql cond- '条件)))
(defun cond-thenp(then-)
  (or (eql then- 'then) (eql then- '那么)))
(defun cond-elsep(else-)
  (or (eql else- 'else) (eql else- '否则)))
(defvar default-else  '(format t "error.~%"))

(defun _cond_gen(ll loc-type merge-list &optional (body-num 0))
  (let ((len (length merge-list))(cond- (nth 0 (nth 0 merge-list)))(cond-v (nth 1 (nth 0 merge-list)))
	(then- (nth 0 (nth 1 merge-list)))(then-v (nth 1 (nth 1 merge-list)))(else- (nth 0 (nth 2 merge-list)))
	(else-v (nth 1 (nth 2 merge-list))))
    (if (and (> len 0) (< len 4))
	(cond ((and (cond-condp cond-)(cond-thenp then-))
	       (cond ((and (eql (car loc-type) 'func-define)(is-body cond-v)(is-mydefine then-v)(is-mydefine else-v))
		      (if (cond-elsep else-)
			  (_edit ll loc-type `((body (cond (,(get-loc ll loc-type body-num) ,then-v )(t ,else-v )) ,body-num)))
			  (_edit ll loc-type `((body (cond (,(get-loc ll loc-type body-num) ,then-v )(t ,default-else )) ,body-num)))))
		     ((and (eql (car loc-type) 'func-define)(is-body then-v)(is-mydefine cond-v)(is-mydefine else-v))
		      (if (cond-elsep else-)
			  (_edit ll loc-type `((body (cond (,cond-v ,(get-loc ll loc-type body-num))(t ,else-v)) ,body-num)))
			  (_edit ll loc-type `((body (cond (,cond-v ,(get-loc ll loc-type body-num))(t ,default-else)) ,body-num)))))
		     ((and (eql (car loc-type) 'func-define)(is-body else-v)(is-mydefine cond-v)(is-mydefine then-v))
		      (if (cond-elsep else-)
			  (_edit ll loc-type `((body (cond (,cond-v ,else-v)(t ,(get-loc ll loc-type body-num))) ,body-num)))))
		     (t (format t "条件语句的归并信息不正确。[if cond then else]~%"))))
	      (t (format t "条件语句的归并列表不符合规则。[~a]~%" merge-list)))
	(format t "条件语句的归并列表元素个数非法。[~a]~%" len))))

(defun _cond_add(ll loc-type merge-list &optional (body-num 1))
  (let ((len (length merge-list))(cond- (nth 0 (nth 0 merge-list)))(cond-v (nth 1 (nth 0 merge-list)))
	(then- (nth 0 (nth 1 merge-list)))(then-v (nth 1 (nth 1 merge-list))))
    (if (and (> len 0) (< len 3))
	(if (and (cond-condp cond-)(cond-thenp then-))
	       (cond ((and (eql (car loc-type) 'func-define)(is-mydefine cond-v)(is-mydefine then-v))
		      (_add ll loc-type `((body (,cond-v ,then-v ) ,body-num))))
		     (t (format t "条件语句的子项增加不符合规则。[~a]~%" merge-list))))
	(format t "条件语句的子项增加的归并列表元素个数非法。[~a]~%" len))))
